package com.itheima.api.array.demo02;

public class SortDemo01 {

    public static void main(String[] args) {

        int[] arr = {12, 34, 56, 11, 10, 9};

        //调用printArr方法
        printArr(arr);
        System.out.println();

        //调用冒泡排序
        bubbleSort(arr);

        //调用printArr方法
        printArr(arr);

    }

    public static void printArr(int[] arr){

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

    }

    public static void bubbleSort(int[] arr){

        for(int x = 0; x < arr.length - 1; x++){

            for (int i = 0; i < arr.length - 1; i++) {

                if(arr[i] > arr[i+1]){
                    int temp = arr[i];
                    arr[i] = arr[i+1];
                    arr[i+1] = temp;
                }

            }
        }

    }

}
